package com.mh.study.streams;

import java.util.Optional;
import java.util.stream.Stream;

/**
 * @author meng.han
 * @since 2022-01-17
 */
public class ReferenceStream {

    public Optional<String> findAny(Stream<String> stream, final String filterStr) {
        return stream.filter(element -> element.contains(filterStr)).findAny();
    }

    public Optional<String> findFirst(Stream<String> stream, final String filterStr) {
        return stream.filter(element -> element.contains(filterStr)).findFirst();
    }

    /**
     * 流不能重复使用
     */
    public void throwIllegalStateException() {
        Stream<String> stream = Stream.of("a", "b", "c");
        Optional<String> any = stream.findAny();
        Optional<String> first = stream.findFirst();
    }

}
